<?php
namespace app\common\logic;

use app\common\model\PettyCashLog;
use app\common\component\parameters\ParametersModel;

class PettyCash {
	public function get() {
		$getParam = ParametersModel::get(['key' => 'PETTY_CASH']);
		return $getParam['value'];
	}

	public function add($user_id) {
		$price = 35;

		$pettyCashLog = new PettyCashLog([
			'user_id' => $user_id,
			'price' => $price,
			'create_time' => time()
		]);

		if($pettyCashLog -> save() && ParametersModel::where('key', 'PETTY_CASH') -> setInc('value', $price)) {
			return [
				'code' => 0,
				'message' => '备用金金额和日志增加成功'
			];
		}
		return [
			'code' => -1,
			'message' => '备用金金额和日志增加失败'
		];
	}
}
?>